<?php
namespace app\admin\controller;
use think\Request;

class ActiveOrder extends Base
{
    protected function _initialize(){
        $this->checkLogin();
        $this->menuLoad();
    }

    public function activeOrderList(){
        $activeOrder = new \app\admin\model\ActiveOrder();
        $where['id'] = ['neq',0];
        $rs = $activeOrder->getPageAll($where);
        $this->assign('rs',$rs);
        return $this->fetch();
    }

    public function editActiveOrder(Request $request){
        $activeOrder = new \app\admin\model\ActiveOrder();
        if($request->post()){
            $data = $request->post();
            $where['id']  = $data['id'];
            unset($data['id']);
            $rs = $activeOrder->edit($where,$data);
            if($rs){
                return $this->success('更新成功');
            }else{
                return $this->error('更新失败');
            }
        }else{
            $where['id'] = $request->get('id');
            $rs = $activeOrder->getOne($where);
            $rs['info'] = json_decode($rs['info'],true);
            $this->assign('rs',$rs);
            return $this->fetch();
        }
    }

}